﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.filters.*;
    import Engine.*;

    public class PaintSelector extends SWFDialog {

        private const SWATCH_SIZE:int = 24;
        private const SWATCH_PADDING:int = 6;
        private const PREVIEWHOLDERWIDTH:Number = 115;
        private const PREVIEWHOLDERHEIGHT:Number = 95;

        private var m_window:MovieClip;
        private var m_accept:GenericButton;
        private var m_close:GenericButton;
        private var m_colors:Array;
        private var m_selectedColor:uint;
        private var m_preview:Sprite;

        public function PaintSelector(){
            var _local3:String;
            this.m_colors = [];
            m_dialogAsset = "assets/dialogs/Paint_Selector.swf";
            var _local1:XML = Global.gameSettings.getXML();
            var _local2:int;
            while (_local2 < _local1.colors.color.length()) {
                _local3 = _local1.colors.color[_local2].@rgb.toString();
                this.m_colors.push({color:Utilities.hexColorToIntColor(_local3)});
                _local2++;
            };
            super(true);
        }
        override protected function onLoadComplete():void{
            var _local7:MovieClip;
            var _local8:ColorTransform;
            this.m_window = (m_loader.content as MovieClip);
            this.m_accept = new GenericButton(this.m_window.paintSelector_mc.ok_bt, this.onOkClick);
            this.m_accept.text = ZLoc.t("Dialogs", "Accept");
            this.m_window.paintSelector_mc.close_bt.addEventListener(MouseEvent.CLICK, this.onCancelClick, false, 0, true);
            var _local1 = 90;
            var _local2:int = _local1;
            var _local3 = 128;
            var _local4 = 130;
            var _local5:Class = (this.m_window.loaderInfo.applicationDomain.getDefinition("paint_bevel") as Class);
            this.m_preview = new Sprite();
            this.m_selectedColor = this.m_colors[0].color;
            this.updatePreview();
            this.m_preview.x = this.m_window.paintSelector_mc.getChildByName("preview_mc").x;
            this.m_preview.y = this.m_window.paintSelector_mc.getChildByName("preview_mc").y;
            this.m_preview.scaleX = (this.PREVIEWHOLDERWIDTH / this.m_preview.width);
            this.m_preview.scaleY = (this.PREVIEWHOLDERHEIGHT / this.m_preview.height);
            this.m_preview.visible = true;
            this.m_window.addChild(this.m_preview);
            var _local6:int;
            while (_local6 < this.m_colors.length) {
                _local7 = new (_local5)();
                _local8 = new ColorTransform();
                _local8.color = this.m_colors[_local6].color;
                _local7.swatch_mc.transform.colorTransform = _local8;
                _local7.filters = [new DropShadowFilter()];
                _local7.x = _local2;
                _local7.y = _local3;
                _local7.addEventListener(MouseEvent.CLICK, this.onClickSwatch);
                this.m_colors[_local6].swatch = _local7;
                this.m_window.addChild(_local7);
                _local2 = (_local2 + (this.SWATCH_SIZE + this.SWATCH_PADDING));
                if ((_local2 - _local1) > _local4){
                    _local2 = _local1;
                    _local3 = (_local3 + (this.SWATCH_SIZE + this.SWATCH_PADDING));
                };
                _local6++;
            };
            addChild(this.m_window);
        }
        protected function updatePreview():void{
            this.m_preview.graphics.beginFill(this.m_selectedColor);
            this.m_preview.graphics.drawRect(0, 0, 20, 20);
            this.m_preview.graphics.endFill();
        }
        private function onClickSwatch(_arg1:MouseEvent):void{
            var _local2:int;
            while (_local2 < this.m_colors.length) {
                if (this.m_colors[_local2].swatch == _arg1.currentTarget){
                    this.m_selectedColor = this.m_colors[_local2].color;
                    this.updatePreview();
                    break;
                };
                _local2++;
            };
        }
        private function onOkClick(_arg1:MouseEvent):void{
            _arg1.stopPropagation();
            close();
            dispatchEvent(new Event("PaintSelector_onOkClick"));
        }
        private function onCancelClick(_arg1:MouseEvent):void{
            _arg1.stopPropagation();
            close();
            dispatchEvent(new Event("PaintSelector_onCancelClick"));
        }
        public function get selectedColor():uint{
            return (this.m_selectedColor);
        }

    }
}//package Display 
